import React, { Component } from 'react';
import { connect } from 'dva';
import SuperForm from '../../components/SuperForm'
import { Form, DatePicker, TimePicker, Button, InputNumber,message } from 'antd';
const config = {
    rules: [{ type: 'object', required: true, message: 'Please select time!' }],
}
const mapStateToProps = (state) => state.exam
@connect(mapStateToProps)

class index extends Component {
    
    get create_form() {

        return [
            {
                label: '试卷名称',
                name: 'title',
                content: 'Input',
                defaultValue: ''
            },
            {
                label: '选择考试类型',
                name: 'exam_id',
                content: 'Select',
                options: this.props.examType.map(item => ({
                    value:item.exam_id,
                    text: item.exam_name
                })),
                style: '150px',
                defaultValue: ''
            },
            {
                label: '选择课程',
                name: 'subject_id',
                content: 'Select',
                options: this.props.subject.map(item => ({
                    value: item.subject_id,
                    text: item.subject_text
                })),
                style: '150px',
                defaultValue: ''
            },
            {
                label: '设置题量',
                name: 'number',
                content: <InputNumber />,
                style: '100px',
                defaultValue: ''
            },
            {
                label: '开始时间',
                name: 'start_time',
                content: 'DatePicker',
                style: '150px',
                defaultValue: '',
                config: config
            },
            {
                label: '结束时间',
                name: 'end_time',
                content: 'DatePicker',
                style: '150px',
                defaultValue: '',
                config: config
            }
        ]
    }
    handlerSubmit = (payload) => {
        console.log(payload)
        this.props.dispatch({
            type: 'exam/createExam',
            payload
        }).then((res)=>{
            console.log(res, '成功')
        })
    }
    render() {
    
        console.log(this.props)
        return (
            <div>
                <SuperForm
                    onSubmit={this.handlerSubmit}
                    items={this.create_form}
                ></SuperForm>

            </div>
        );
    }
}

export default index